package com.rbw.persist.dao.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.rbw.model.FavoriteBean;
import com.rbw.model.UserBean;
import com.rbw.persist.dao.UserDao;

/**
 * 用户数据库操作
 * 
 * @author cuihaidong
 *
 */
@Repository
public class UserImpl extends BaseImpl implements UserDao {

	final String NAME_SPACE = NAME_SPACE_HEADER + ".UserMapper";

	@Override
	public UserBean selectOneByPhone(String phone) {
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectOneByPhone", phone);
	}

	@Override
	public UserBean selectOneByEmail(String email) {
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectOneByEmail", email);
	}

	@Override
	public UserBean selectOne(String uid) {
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectOneByUid", uid);
	}

	@Override
	public int insert(UserBean data) {
		return sqlSessionTemplate.insert(NAME_SPACE + ".insert", data);
	}

	@Override
	public int update(UserBean data) {
		return sqlSessionTemplate.update(NAME_SPACE + ".update", data);
	}

	@Override
	public int insertFavorite(FavoriteBean f) {
		return sqlSessionTemplate.insert(NAME_SPACE + ".insertFavorite", f);
	}

	@Override
	public FavoriteBean selectFavoriteByUid(String uid, String targetId) {
		Map<String, Object> param = new HashMap<>();
		param.put("userId", uid);
		param.put("targetId", targetId);
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectFavoriteByUid", param);
	}

	@Override
	public int updateFavorite(FavoriteBean f) {
		return sqlSessionTemplate.update(NAME_SPACE + ".updateFavorite", f);
	}

}
